package com.showtao.common.util;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.ser.std.SerializerBase;

public class SimpleDateSerializer extends SerializerBase<Date> {

    private SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
    
    public SimpleDateSerializer() {
        super(Date.class);
    }
    
    protected SimpleDateSerializer(Class<Date> d) {
        super(d);
    }

    @Override
    public void serialize(Date date, JsonGenerator jgen, SerializerProvider provider) throws IOException,
            JsonGenerationException {
        jgen.writeString(date != null ? sdf.format(date) : "");
    }

}
